package com.lanou.mynews.movie;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.android.volley.toolbox.ImageLoader;
import com.lanou.mynews.R;


import java.lang.ref.ReferenceQueue;
import java.util.List;


public class PhotoAdapter extends BaseAdapter{

    private Context mContext;
    private ReferenceQueue requestQueue;
    private List<Content.FilmListEntity.PictureListEntity> picture;

    public PhotoAdapter(Context c, List<Content.FilmListEntity.PictureListEntity> datas){
        this.picture = datas;
        mContext = c;
        Log.i("lanou", "拉取数据");



    }







    @Override
    public int getCount() {
        if (picture != null&& picture.size()>0)
            return picture.size();
        return 0;
    }

    @Override
    public Content.FilmListEntity.PictureListEntity getItem(int position) {
        if (picture != null&&picture.size()>0)
            return picture.get(position);
        else

            return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.photo,null);
            holder = new ViewHolder();


            holder.imageView = (ImageView) convertView.findViewById(R.id.imageView);

            convertView.setTag(holder);

        }else {
            holder = (ViewHolder) convertView.getTag();


        }
        Content.FilmListEntity.PictureListEntity filmListEntity = getItem(position);
        if (filmListEntity != null){

            ImageLoader.ImageListener listener = ImageLoader.getImageListener(holder.imageView,
                    R.drawable.loading, R.drawable.loading);
            ImageLoader imageLoader = VolleySingleton.getInstance(mContext).
                    getImageLoader();
            imageLoader.get(filmListEntity.getPictureAddress(),listener);

        }




        return convertView;
    }
    private class ViewHolder{
        public ImageView imageView;


    }
}
